﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Expert_ExpertYijia : System.Web.UI.Page
{

    private const int GridColumnIndexOfGoodsId = 0;
    private const int GridColumnIndexOfProductCode = 1;
    private const int GridColumnIndexOfProductName = 2;
    private const int GridColumnIndexOfMedicinemodel = 3;
    private const int GridColumnIndexOfOutlookc = 4;
    private const int GridColumnIndexOffactor = 5;
    private const int GridColumnIndexOfQualityLevels = 6;
    private const int GridColumnIndexOfCompanyNameSC = 7;
    private const int GridColumnIndexOfCompanyNameTB = 8;
    private const int GridColumnIndexOfUserCodeTB = 9;
    private const int GridColumnIndexOfSPLimitPrice = 10;
    private const int GridColumnIndexOfSPPrice = 11;
    private const int GridColumnIndexOfExpertPrice1 = 12;
    private const int GridColumnIndexOfExpertPrice1W = 13;
    private const int GridColumnIndexOfYiJiaPackPrice1 = 14;
    private const int GridColumnIndexOfExpertPrice2 = 15;
    private const int GridColumnIndexOfExpertPrice2W = 16;
    private const int GridColumnIndexOfYiJiaPackPrice2 = 17;
    
    private const int GridColumnIndexOfExpertIdea = 18;
    private const int GridColumnIndexOfExpertIdeaW = 19;
    private const int GridColumnIndexOfCompanyIdea = 20;
    private const int GridColumnIndexOfAcceptCompany = 21;
    private const int GridColumnIndexOfAcceptCompanyW = 22;
    private const int GridColumnIndexOfbidid = 23;
    private const int GridColumnIndexOfSubmit = 24;
    private const int GridColumnIndexOfYiJiaBidPrice = 25;
  
    public string _strNone = "block";
    string _strProjectId = "";
    string _strUserType = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumHMedicine);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumZMedicine);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            labMsg.Text = "";
            labMsg.Visible = false;

            //if (txtUserCode.Text.Trim() == "" && txtCompanyNameTB.Text.Trim() == "")
            //{
            //    Response.Write("<script>window.alert('投标人注册号或投标人名称不能为空！');</script>");
            //    return;
            //}
            if (!IsPostBack)
            {
                Db db = new Db();
                string strSql = "select projectid,ProjectMarker,Title from project order by projectid desc";
                System.Data.IDataReader dr = db.DataReader(strSql);
                listProject.DataSource = dr;
                listProject.DataTextField = "Title";
                listProject.DataValueField = "projectid";
                listProject.DataBind();
                dr.Close();
                dr.Dispose();
                db.Close();

                db = new Db();
                strSql = "select top 1 submit from V_Bargaining where checkstatus=1 and  ProjectId='" + listProject.SelectedValue + "'";
                System.Data.IDataReader dr2 = db.DataReader(strSql);
                while (dr2.Read())
                {
                    hf.Value = SysFun.ToTrim(dr2[0]);
                }
                dr2.Close();
                dr2.Dispose();
                db.Close();

                db = new Db();
                strSql = "SELECT MAX(ISNULL(Submit,0)) FROM Bargaining";
                 dr2 = db.DataReader(strSql);
                while (dr2.Read())
                {
                    if (dr2[0] != null && dr2[0].ToString().Equals("3"))
                    {
                        Bexcle.Visible = true;
                    }
                }
                dr2.Close();
                dr2.Dispose();
                db.Close();

                LstCompanyTBADD();
            }
            _strProjectId = listProject.SelectedValue;
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {
                _strUserType = SysFun.ToTrim(_Account.Type);

                //将建限价提交给投标人
                if (Request.Form["subExpertPrice"] == "将建限价提交给投标人" || Request.Form["subExpertPrice"] == "&#23558;&#24314;&#35758;&#20215;&#25552;&#20132;&#32473;&#25237;&#26631;&#20154;")
                {
                    UpdateSubmit();
                }
                SelectSubmit();

                if (Request.Form["SaveCPrice"] == "保存本页专家建限价" || Request.Form["SaveCPrice"] == "&#20445;&#23384;&#26412;&#39029;&#19987;&#23478;&#24314;&#35758;&#20215;")
                {

                    string s = "";
                    //ErrorMsg.Text = "";
                    Db db = new Db();
                    string strSql = "select YiJiaPackPrice1 from Bargaining where YiJiaSwitch=1 and Submit='" + hf.Value + "' ";
                    string num = "1";
                    if (hf.Value == "1")
                    {
                        num = "2";
                    }

                    System.Data.IDataReader dr = db.DataReader(strSql);

                    dr.Close();
                    dr.Dispose();
                    db.Close();

                    foreach (GridViewRow row in GridView2.Rows)
                    {
                        if (row.RowType == DataControlRowType.DataRow)
                        {

                            string a = Request.Form["txt" + row.Cells[GridColumnIndexOfbidid].Text];
                            string _strExpertidea = SysFun.ToTrim(Request.Form["txtExpertIdea" + row.Cells[GridColumnIndexOfbidid].Text]).Replace("&nbsp;", "");
                            if (!SysFun.IsNumeric(a))
                            {
                                //ErrorMsg.Text += row.Cells[GridColumnIndexOfGoodsId].Text + "专家建限价2只能为数字";
                                Response.Write("<script>window.alert('专家建限价" + num + "只能为数字！');</script>");
                            }
                            else
                            {
                                a = Convert.ToDecimal(a).ToString("N2");
                                if (SysFun.ToDec(a) < 0 || SysFun.ToDec(a) > 99999999)
                                {
                                    //ErrorMsg.Text += row.Cells[GridColumnIndexOfGoodsId].Text + "专家建限价2数据有误";
                                    Response.Write("<script>window.alert('专家建限价" + num + "数据有误！');</script>");
                                }
                                else
                                {
                                    if (hf.Value == "-1")//专家报建限价1
                                    {
                                        if (SysFun.ToDec(a) > SysFun.ToDec(row.Cells[GridColumnIndexOfSPPrice].Text))
                                        {
                                            Response.Write("<script>window.alert('专家建限价" + num + "不能高于投标报价！');</script>");
                                        }
                                        else
                                        {
                                            if (a != row.Cells[GridColumnIndexOfExpertPrice1W].Text.ToString())
                                            {
                                                s += "@" + "update Bargaining set ExpertPrice1=" + a.Replace(",", "") + ",AccountId_ZJ=" + _Account.AccountId + " ,OperatorDateTime=getdate(),ExpertIdea='" + _strExpertidea + "' where Submit<0 and bidid=" + row.Cells[GridColumnIndexOfbidid].Text;
                                            }
                                        }
                                    }
                                    else if (hf.Value == "2")//专家报建限价2
                                    {
                                        if (SysFun.ToDec(a) > SysFun.ToDec(row.Cells[GridColumnIndexOfYiJiaPackPrice1].Text))
                                        {
                                            //ErrorMsg.Text += row.Cells[GridColumnIndexOfGoodsId].Text + "专家建限价2不能高于限价报价";
                                            Response.Write("<script>window.alert('专家建限价" + num + "不能高于限价报价！');</script>");
                                        }
                                        else
                                        {
                                            //判断当前价格是否被修改过，如果没有修改，就不将此价格放到提交列表中

                                            if (a != row.Cells[GridColumnIndexOfExpertPrice2W].Text.ToString())
                                            {
                                                s += "@" + "update Bargaining set ExpertPrice2=" + a.Replace(",", "") + ",AccountId_ZJ=" + _Account.AccountId + " ,OperatorDateTime=getdate(),ExpertIdea='" + _strExpertidea + "' where Submit<3 and bidid=" + row.Cells[GridColumnIndexOfbidid].Text;
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }
                    Db db2 = new Db();
                    if (s.Length > 0)
                    {
                        db2.ExecuteTransaction(s.Substring(1).Split(new char[] { '@' }), 30);
                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "修改", "Bargaining", s, "../Agency/ExpertYijia.aspx");

                        //ErrorMsg.Text += "本页专家建限价2成功";
                    }
                    db2.Close();


                }
                showGridView();
            }
        }

    }
    public void showGridView()
    {
        string _strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "V_Bargaining";                                               //要查询的表明
        dbPage.Key = "Bidid";                                               //表的主键    
        dbPage.Where = _strConditions;                                           //查询条件    
        dbPage.SelectField = " YiJiaSwitch,bidid,GoodsId, ProductCode, ProductName, Medicinemodel, Outlookc, Factor,  case qualitylevels  " + ConfigurationManager.AppSettings["QualityLevels"].ToString() + " end as qualitylevels, CompanyName_sc, UserCode_sc, CompanyName_TB, UserCode_TB, SPPrice, LimitPrice, ExpertPrice1, YiJiaPackPrice1,YiJiaPackPrice2, ExpertPrice2, Accept_Company, Submit,CompanyIdea,ExpertIdea,YiJiaBidPrice ";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "ProductCode,Bidid";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        
        GridView2.DataSource = dr;
        GridView2.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
       
    }
    public string fctConditions()
    {
        string _strWhere;
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {

            _strWhere = " checkstatus=1 and  ProjectId=" + _strProjectId + "  And";
            // _strWhere += GetWhereUserType(_strUserType) + " and";
            if (lstCompanyNameTB.Items.Count > 0)
            {
                _strWhere += "  AccountId_TB=" + lstCompanyNameTB.SelectedValue + " And";
            }
            else
            {
                //投标人名称

                string _strCompanyNameTB = txtCompanyNameTB.Text.Trim();
                if (_strCompanyNameTB != "")
                {
                    _strWhere += " CompanyName_TB= '" + _strCompanyNameTB + "' And";
                }

                //投标人注册号 UserCode_TB
                //string _strUserCodeTB = txtUserCode.Text.Trim();
                //if (_strUserCodeTB != "")
                //{
                //    _strWhere += " UserCode_TB= '" + _strUserCodeTB + "' And";
                //}
            }
            //药品通用名

            string _strProductName = SysFun.ToTrim(txtProductName.Text);
            if (_strProductName != "")
            {
                _strWhere += " ProductName like '%" + _strProductName + "%' And";
            }
            //药品流水号

            string _strGoodsid = txtGoodsId.Text.Trim();
            if (_strGoodsid != "")
            {
                _strWhere += " Goodsid ='" + _strGoodsid + "' And";
            }

            //生产企业名称
            string _strCompanyNameSC = txtCompanyNameSC.Text.Trim();
            if (_strCompanyNameSC != "")
            {
                _strWhere += " CompanyName_sc like '%" + _strCompanyNameSC + "%' And";
            }
            //限价专家建限价2
            string _strAcceptCompany = lstAcceptCompany.SelectedValue;
            if (hf.Value == "-1")//专家报建限价1
            {
                switch (_strAcceptCompany)
                {
                    case "0"://全部
                        break;
                    case "1"://企业已接受专家建限价
                        _strWhere += " (Accept_Company=1 OR Accept_Company=2)  And";
                        break;
                    case "2"://未接受已给限价
                        _strWhere += " (accept_company=0 or accept_company is null) and expertprice1>0 And";
                        break;
                    case "3"://未接受未给限价
                        _strWhere += " (accept_company=0 or accept_company is null) and (expertprice1=0 or expertprice1 is null)  And";
                        break;
                }
            }
            else if (hf.Value == "1")//专家报建限价2
            {
                switch (_strAcceptCompany)
                {
                    case "0"://全部
                        break;
                    case "1"://企业已接受专家建限价
                        //
                        _strWhere += " (Accept_Company=1 OR Accept_Company=2)  And";
                        break;
                    case "2"://未接受已给限价

                        _strWhere += " (accept_company=0 or accept_company is null) and expertprice2>0 And";
                        break;
                    case "3"://未接受未给限价

                        _strWhere += " (accept_company=0 or accept_company is null) and (expertprice2=0 or expertprice2 is null)  And";
                        break;
                }
            }

            if (_strWhere != "")
            {
                _strWhere = "  " + _strWhere.Substring(0, _strWhere.Length - 3);
            }
        }
        else
        {
            _strWhere = "";

        }
        return _strWhere;
    }

    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //如果专家接受的企业的报价,或企业接受专家的报价那么就不用显示文本框
            string _strSubmit = e.Row.Cells[GridColumnIndexOfSubmit].Text;
            switch (_strSubmit)
            {
                case "-1":
                    //输入一次建限价和专家建议
                    //此时：专家建限价1和专家意见，可见；限价报价、企业意见、专家建限价2、限价中标价、企业是否接受 ,不可见
                    e.Row.Cells[GridColumnIndexOfExpertPrice1].Text = "<input type='text' style='width:80px' name='txt" + e.Row.Cells[GridColumnIndexOfbidid].Text + "' value='" + SysFun.ToDec(e.Row.Cells[GridColumnIndexOfExpertPrice1W].Text) + "' /> ";
                    e.Row.Cells[GridColumnIndexOfExpertIdea].Text = "<textarea  style='height:50' name='txtExpertIdea" + e.Row.Cells[GridColumnIndexOfbidid].Text.Trim() + "' >" + e.Row.Cells[GridColumnIndexOfExpertIdeaW].Text.Trim().Replace("&nbsp;", "") + "</textarea>";
                    e.Row.Cells[GridColumnIndexOfExpertPrice1].Visible = true;
                    e.Row.Cells[GridColumnIndexOfYiJiaPackPrice1].Visible = false;
                    e.Row.Cells[GridColumnIndexOfExpertPrice2].Visible = false;
                    e.Row.Cells[GridColumnIndexOfExpertIdea].Visible = true;
                    e.Row.Cells[GridColumnIndexOfCompanyIdea].Visible = false;
                    e.Row.Cells[GridColumnIndexOfYiJiaBidPrice].Visible = false;
                    e.Row.Cells[GridColumnIndexOfAcceptCompany].Visible = false;
                   
                    break;

                case "0"://当企业没有提交限价报价时：限价报价、企业意见、专家建限价2、专家意见和限价中标价，都不可见
                    e.Row.Cells[GridColumnIndexOfExpertPrice1].Text = e.Row.Cells[GridColumnIndexOfExpertPrice1W].Text;
                    e.Row.Cells[GridColumnIndexOfExpertIdea].Text = e.Row.Cells[GridColumnIndexOfExpertIdeaW].Text;
                    e.Row.Cells[GridColumnIndexOfYiJiaPackPrice1].Visible = false;
                    e.Row.Cells[GridColumnIndexOfCompanyIdea].Visible = false;
                    e.Row.Cells[GridColumnIndexOfExpertPrice2].Visible = false;
                    e.Row.Cells[GridColumnIndexOfExpertIdea].Visible = true;
                    e.Row.Cells[GridColumnIndexOfYiJiaBidPrice].Visible = false;
                    
                    break;
                case "1":
                    //企业已经将限价报价提交给专家那么，专家就可以输入二次建限价和专家建议
                    //此时：限价报价、企业意见、专家建限价2和专家意见，可见；限价中标价不可见
         

                    if (e.Row.Cells[GridColumnIndexOfAcceptCompanyW].Text == "0")
                    {
                        //如果企业没有接受专家的第一次建限价，那么就让专家输入第二次建限价和专家建议
                        e.Row.Cells[GridColumnIndexOfExpertPrice2].Text = "<input type='text' style='width:80px' name='txt" + e.Row.Cells[GridColumnIndexOfbidid].Text + "' value='" + SysFun.ToDec(e.Row.Cells[GridColumnIndexOfExpertPrice2W].Text) + "' /> ";
                        e.Row.Cells[GridColumnIndexOfExpertIdea].Text = "<textarea  style='height:50' name='txtExpertIdea" + e.Row.Cells[GridColumnIndexOfbidid].Text.Trim() + "' >" + e.Row.Cells[GridColumnIndexOfExpertIdeaW].Text.Trim().Replace("&nbsp;", "") + "</textarea>";

                    }
                    else
                    {
                   
                        //如果企业已经接受了专家的建议，那么就不用专家来输入第二次建限价和专家建议
                        e.Row.Cells[GridColumnIndexOfExpertPrice2].Text = e.Row.Cells[GridColumnIndexOfExpertPrice2W].Text;
                        e.Row.Cells[GridColumnIndexOfExpertIdea].Text = e.Row.Cells[GridColumnIndexOfExpertIdeaW].Text;
                    }
                    e.Row.Cells[GridColumnIndexOfExpertPrice1].Text = e.Row.Cells[GridColumnIndexOfExpertPrice1W].Text;
                    e.Row.Cells[GridColumnIndexOfYiJiaPackPrice1].Visible = true;
                    e.Row.Cells[GridColumnIndexOfCompanyIdea].Visible = true;
                    e.Row.Cells[GridColumnIndexOfExpertPrice2].Visible = true;
                    e.Row.Cells[GridColumnIndexOfExpertIdea].Visible = true;
                    e.Row.Cells[GridColumnIndexOfYiJiaBidPrice].Visible = false;
                    break;
                case "2":
                    //专家将专家建限价提交给投标人，专家就不用做任何操作了。

                    //此时：限价报价、企业意见、专家建限价2和专家意见，可见；限价中标价不可见
                    if (e.Row.Cells[GridColumnIndexOfAcceptCompanyW].Text == "0")
                    {
                        //如果企业没有接受专家的第一次建限价，那么就让专家输入第二次建限价和专家建议
                        e.Row.Cells[GridColumnIndexOfExpertPrice2].Text = "<input type='text' style='width:80px' name='txt" + e.Row.Cells[GridColumnIndexOfbidid].Text + "' value='" + SysFun.ToDec(e.Row.Cells[GridColumnIndexOfExpertPrice2W].Text) + "' /> ";
                        e.Row.Cells[GridColumnIndexOfExpertIdea].Text = "<textarea  style='height:50' name='txtExpertIdea" + e.Row.Cells[GridColumnIndexOfbidid].Text.Trim() + "' >" + e.Row.Cells[GridColumnIndexOfExpertIdeaW].Text.Trim().Replace("&nbsp;", "") + "</textarea>";

                    }
                    else
                    {

                        //如果企业已经接受了专家的建议，那么就不用专家来输入第二次建限价和专家建议
                        e.Row.Cells[GridColumnIndexOfExpertPrice2].Text = e.Row.Cells[GridColumnIndexOfExpertPrice2W].Text;
                        e.Row.Cells[GridColumnIndexOfExpertIdea].Text = e.Row.Cells[GridColumnIndexOfExpertIdeaW].Text;
                    }

                   
                    e.Row.Cells[GridColumnIndexOfExpertPrice1].Text = e.Row.Cells[GridColumnIndexOfExpertPrice1W].Text;
                    e.Row.Cells[GridColumnIndexOfCompanyIdea].Visible = true;
                    e.Row.Cells[GridColumnIndexOfExpertPrice2].Visible = true;
                    e.Row.Cells[GridColumnIndexOfExpertIdea].Visible = true;
                    e.Row.Cells[GridColumnIndexOfYiJiaBidPrice].Visible = false;
                    break;
                case "3":
                    //企业已经将最终的限价结果提交给了专家。

                    //此时：限价报价、企业意见、专家建限价2、专家意见和限价中标价，都可见

                    e.Row.Cells[GridColumnIndexOfExpertPrice1].Text = e.Row.Cells[GridColumnIndexOfExpertPrice1W].Text;
                    e.Row.Cells[GridColumnIndexOfExpertPrice2].Text = e.Row.Cells[GridColumnIndexOfExpertPrice2W].Text;
                    e.Row.Cells[GridColumnIndexOfExpertIdea].Text = e.Row.Cells[GridColumnIndexOfExpertIdeaW].Text;
                    e.Row.Cells[GridColumnIndexOfExpertPrice2].Text = e.Row.Cells[GridColumnIndexOfExpertPrice2W].Text;
                    e.Row.Cells[GridColumnIndexOfExpertIdea].Text = e.Row.Cells[GridColumnIndexOfExpertIdeaW].Text;
                    e.Row.Cells[GridColumnIndexOfYiJiaPackPrice1].Visible = true;
                    e.Row.Cells[GridColumnIndexOfCompanyIdea].Visible = true;
                    e.Row.Cells[GridColumnIndexOfExpertPrice2].Visible = true;
                    e.Row.Cells[GridColumnIndexOfExpertIdea].Visible = true;
                    e.Row.Cells[GridColumnIndexOfYiJiaBidPrice].Visible = true;

                    break;
            }
            if (e.Row.Cells[GridColumnIndexOfAcceptCompanyW].Text == "0")
            {
                e.Row.Cells[GridColumnIndexOfAcceptCompany].Text = "否";
            }
            else
            {
                e.Row.Cells[GridColumnIndexOfAcceptCompany].Text = "是";
            }

        }
        e.Row.Cells[GridColumnIndexOfExpertPrice1W].Visible = false;
        e.Row.Cells[GridColumnIndexOfExpertIdeaW].Visible = false;
        e.Row.Cells[GridColumnIndexOfExpertPrice2W].Visible = false;
        e.Row.Cells[GridColumnIndexOfAcceptCompanyW].Visible = false;
        e.Row.Cells[GridColumnIndexOfbidid].Visible = false;
        e.Row.Cells[GridColumnIndexOfSubmit].Visible = false;
    }
    /// <summary>
    /// 
    /// </summary>
    private void UpdateSubmit()
    {
        if (hf.Value == "-1")//专家报建限价1
        {
            Db db = new Db();
            //取出投标人注册号
            string strWhere = "";// GetWhereUserType(_strUserType) + " and"; 
            if (lstCompanyNameTB.Items.Count > 0)
            {
                strWhere += "  AccountId_TB=" + lstCompanyNameTB.SelectedValue;
            }
            //else
            //{
            //    strWhere += "  UserCode_TB='" + txtUserCode.Text.Trim() + "'";
            //}

            //查找出是否还有，没给限价的

            string _strGoodsId = "";
            string strSql = "select top 10 goodsid  from V_Bargaining  where checkstatus=1 and (accept_company=0 or accept_company is null) and (expertprice1=0 or expertprice1 is null) and  " + strWhere;
            System.Data.IDataReader dr = db.DataReader(strSql);
            while (dr.Read())
            {
                _strGoodsId += SysFun.ToTrim(dr["goodsid"]) + "，";
            }
            dr.Close();
            dr.Dispose();
            //如果没有那么就将专家的建限价提交给投标人
            if (_strGoodsId == "")
            {
                strSql = "update V_Bargaining set submit=0 where submit=-1 and " + strWhere;
                db.Command(strSql);
                labMsg.Text = "";
                labMsg.Visible = false;
            }
            else
            {
                //否则提示他，还有那些流水号没有给限价
                labMsg.Text = "已下的流水号还没有给限价，请给完限价再提交：" + _strGoodsId;
                labMsg.Visible = true;
            }
            db.Close();
        }
        else if (hf.Value == "1")//专家报建限价2
        {
            Db db = new Db();
            //取出投标人注册号
            string strWhere = "";// GetWhereUserType(_strUserType) + " and"; 
            if (lstCompanyNameTB.Items.Count > 0)
            {
                strWhere += "  AccountId_TB=" + lstCompanyNameTB.SelectedValue;
            }
            //else
            //{
            //    strWhere += "  UserCode_TB='" + txtUserCode.Text.Trim() + "'";
            //}

            //查找出是否还有，没给限价的

            string _strGoodsId = "";
            string strSql = "select  top 10 goodsid  from V_Bargaining  where checkstatus=1 and (accept_company=0 or accept_company is null) and (expertprice2=0 or expertprice2 is null) and  " + strWhere;
            System.Data.IDataReader dr = db.DataReader(strSql);
            while (dr.Read())
            {
                _strGoodsId += SysFun.ToTrim(dr["goodsid"]) + "，";
            }
            dr.Close();
            dr.Dispose();
            //如果没有那么就将专家的建限价提交给投标人
            if (_strGoodsId == "")
            {
                strSql = "update V_Bargaining set submit=2 where submit=1 and " + strWhere;
                db.Command(strSql);
                labMsg.Text = "";
                labMsg.Visible = false;
            }
            else
            {
                //否则提示他，还有那些流水号没有给限价
                labMsg.Text = "已下的流水号还没有给限价，请给完限价再提交：" + _strGoodsId;
                labMsg.Visible = true;
            }
            db.Close();
        }
    }
    private void SelectSubmit()
    {
        //判断当前的提交状态，
        Db db = new Db();
        string strWhere = "";
        //  strWhere = GetWhereUserType(_strUserType) +" and";
        if (lstCompanyNameTB.Items.Count > 0)
        {
            strWhere += " where AccountId_TB=" + lstCompanyNameTB.SelectedValue;
        }
        //else if (txtUserCode.Text.Trim() != "")
        //{
        //    strWhere += " where UserCode_TB='" + txtUserCode.Text.Trim() + "'";
        //}
        string _strSubmit = "";
        string strSql = "select  top 1 submit  from V_Bargaining " + strWhere;
        System.Data.IDataReader dr = db.DataReader(strSql);
        if (dr.Read())
        {
            _strSubmit = SysFun.ToTrim(dr["submit"]);
        }
        dr.Close();
        dr.Dispose();
        db.Close();
        switch (_strSubmit)
        {
            case "-1":
                //输入一次建限价和专家建议
                //此时：专家建限价1和专家意见，可见；限价报价、企业意见、专家建限价2、限价中标价、企业是否接受 ,不可见
                _strNone = "block";
                Label1.Text = "<input name='subExpertPrice' type='submit' value='将建限价提交给投标人' class='button_bg8' style='width: 120px; height: 18px;' onclick='javascript:return CheckForm()' id='Submit1'  />";
                labSave.Text = "<input name='SaveCPrice' type='submit' value='保存本页专家建限价' class='button_bg8' style='width: 120px; height: 18px;' onclick='javascript:return CheckForm()' />";
                GridView2.Columns[GridColumnIndexOfExpertPrice1].Visible = true;
                GridView2.Columns[GridColumnIndexOfYiJiaPackPrice1].Visible = false;
                GridView2.Columns[GridColumnIndexOfCompanyIdea].Visible = false;
                GridView2.Columns[GridColumnIndexOfExpertPrice2].Visible = false;
                GridView2.Columns[GridColumnIndexOfExpertIdea].Visible = true;
                GridView2.Columns[GridColumnIndexOfYiJiaBidPrice].Visible = false;
                GridView2.Columns[GridColumnIndexOfAcceptCompany].Visible = false;
                GridView2.Columns[GridColumnIndexOfYiJiaPackPrice2].Visible = false;
                break;

            case "0"://当企业没有提交限价报价时：限价报价、企业意见、专家建限价2、专家意见和限价中标价，都不可见
                _strNone = "none";
                Label1.Text = "";
                labSave.Text = "";
                GridView2.Columns[GridColumnIndexOfYiJiaPackPrice1].Visible = false;
                GridView2.Columns[GridColumnIndexOfCompanyIdea].Visible = false;
                GridView2.Columns[GridColumnIndexOfExpertPrice2].Visible = false;
                GridView2.Columns[GridColumnIndexOfExpertIdea].Visible = true;
                GridView2.Columns[GridColumnIndexOfYiJiaBidPrice].Visible = false;
                
                break;
            case "1":
                //企业已经将限价报价提交给专家那么，专家就可以输入二次建限价和专家建议
                //此时：限价报价、企业意见、专家建限价2和专家意见，可见；限价中标价不可见

                _strNone = "block";
                Label1.Text = "<input name='subExpertPrice' type='submit' value='将建限价提交给投标人' class='button_bg8' style='width: 120px; height: 18px;' onclick='javascript:return CheckForm()' id='Submit1'  />";
                labSave.Text = "<input name='SaveCPrice' type='submit' value='保存本页专家建限价' class='button_bg8' style='width: 120px; height: 18px;' onclick='javascript:return CheckForm()' />";
                GridView2.Columns[GridColumnIndexOfExpertPrice1].Visible = true;
                GridView2.Columns[GridColumnIndexOfYiJiaPackPrice1].Visible = true;
                GridView2.Columns[GridColumnIndexOfCompanyIdea].Visible = true;
                GridView2.Columns[GridColumnIndexOfExpertPrice2].Visible = true;
                GridView2.Columns[GridColumnIndexOfExpertIdea].Visible = true;
                GridView2.Columns[GridColumnIndexOfYiJiaBidPrice].Visible = false;

                break;
            case "2":
                //专家将专家建限价提交给投标人，专家就不用做任何操作了。

                //此时：限价报价、企业意见、专家建限价2和专家意见，可见；限价中标价不可见

                _strNone = "none";
                Label1.Text = "<input name='subExpertPrice' type='submit' value='将建限价提交给投标人' class='button_bg8' style='width: 120px; height: 18px;' onclick='javascript:return CheckForm()' id='Submit1'  />";
                labSave.Text = "<input name='SaveCPrice' type='submit' value='保存本页专家建限价' class='button_bg8' style='width: 120px; height: 18px;' onclick='javascript:return CheckForm()' />";
              
                GridView2.Columns[GridColumnIndexOfYiJiaPackPrice1].Visible = true;
                GridView2.Columns[GridColumnIndexOfCompanyIdea].Visible = true;
                GridView2.Columns[GridColumnIndexOfExpertPrice2].Visible = true;
                GridView2.Columns[GridColumnIndexOfExpertIdea].Visible = true;
                GridView2.Columns[GridColumnIndexOfYiJiaBidPrice].Visible = false;
                break;
            case "3":
                //企业已经将最终的限价结果提交给了专家。

                //此时：限价报价、企业意见、专家建限价2、专家意见和限价中标价，都可见

                _strNone = "none";
                Label1.Text = "";
                labSave.Text = "";
                GridView2.Columns[GridColumnIndexOfYiJiaPackPrice1].Visible = true;
                GridView2.Columns[GridColumnIndexOfCompanyIdea].Visible = true;
                GridView2.Columns[GridColumnIndexOfExpertPrice2].Visible = true;
                GridView2.Columns[GridColumnIndexOfExpertIdea].Visible = true;
                GridView2.Columns[GridColumnIndexOfYiJiaBidPrice].Visible = true;
                break;
        }

    }
    private void LstCompanyTBADD()
    {
        //刷新待处理企业名单

        lstCompanyNameTB.ClearSelection();
        Db db = new Db();
        string strWhere = GetWhere();
        string strSql = "select distinct  usercode_tb ,AccountId_TB from (select usercode_tb ,AccountId_TB from V_Bargaining where checkstatus=1 and  projectid='" + listProject.SelectedValue + "' " + strWhere + ") AA ";
        System.Data.IDataReader dr = db.DataReader(strSql);
        lstCompanyNameTB.DataSource = dr;
        lstCompanyNameTB.DataTextField = "usercode_tb";
        lstCompanyNameTB.DataValueField = "AccountId_TB";
        lstCompanyNameTB.DataBind();
        dr.Close();
        dr.Dispose();
        db.Close();

    }
    private string GetWhere()
    {
        string _strWhere = "";
        if (hf.Value == "-1")
        {
            switch (rbtnSub.SelectedIndex)
            {
                case 1:
                    _strWhere = " and submit=0";
                    break;
                case 2:
                    _strWhere = " and submit=-1";
                    break;
            }
        }
        else if (hf.Value == "1")
        {
            switch (rbtnSub.SelectedIndex)
            {
                case 1:
                    _strWhere = " and submit=2";
                    break;
                case 2:
                    _strWhere = " and submit=1";
                    break;
            }
        }
        return _strWhere;
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        //刷新待处理企业名单

        LstCompanyTBADD();
    }
    protected void Bexcle_Click(object sender, EventArgs e)
    {
        string _string = "select * from V_Bargaining where  checkstatus=1 and  ProjectId=" + _strProjectId + "  And  Accept_Company=0 ";
        Db db = new Db();
        GridView2.DataSource = db.DataTable(_string);
        GridView2.DataBind();
        db.Close();
        string filename = "未同意产品.xls";
        SysFun.WriteToExcel(GridView2, this.Page, filename);
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        //OverRide　为了使导出成Excel可行！

    }
}
